package com.jhs.boot.system.controller;

import com.jhs.boot.system.service.SysNodesDhcpService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jhs.boot.system.model.form.SysNodesDhcpForm;
import com.jhs.boot.system.model.query.SysNodesDhcpQuery;
import com.jhs.boot.system.model.vo.SysNodesDhcpVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jhs.boot.common.result.PageResult;
import com.jhs.boot.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 节点IP匹配前端控制层
 *
 * @author youlaitech
 * @since 2025-10-29 12:50
 */
@Tag(name = "节点IP匹配接口")
@RestController
@RequestMapping("/api/v1/sys-nodes-dhcp")
@RequiredArgsConstructor
public class SysNodesDhcpController  {

    private final SysNodesDhcpService sysNodesDhcpService;

    @Operation(summary = "节点IP匹配分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('ap:sys-nodes-dhcp:query')")
    public PageResult<SysNodesDhcpVO> getSysNodesDhcpPage(SysNodesDhcpQuery queryParams ) {
        IPage<SysNodesDhcpVO> result = sysNodesDhcpService.getSysNodesDhcpPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增节点IP匹配")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('ap:sys-nodes-dhcp:add')")
    public Result<Void> saveSysNodesDhcp(@RequestBody @Valid SysNodesDhcpForm formData ) {
        boolean result = sysNodesDhcpService.saveSysNodesDhcp(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取节点IP匹配表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('ap:sys-nodes-dhcp:edit')")
    public Result<SysNodesDhcpForm> getSysNodesDhcpForm(
        @Parameter(description = "节点IP匹配ID") @PathVariable Long id
    ) {
        SysNodesDhcpForm formData = sysNodesDhcpService.getSysNodesDhcpFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改节点IP匹配")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('ap:sys-nodes-dhcp:edit')")
    public Result<Void> updateSysNodesDhcp(
            @Parameter(description = "节点IP匹配ID") @PathVariable Long id,
            @RequestBody @Validated SysNodesDhcpForm formData
    ) {
        boolean result = sysNodesDhcpService.updateSysNodesDhcp(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除节点IP匹配")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('ap:sys-nodes-dhcp:delete')")
    public Result<Void> deleteSysNodesDhcps(
        @Parameter(description = "节点IP匹配ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = sysNodesDhcpService.deleteSysNodesDhcps(ids);
        return Result.judge(result);
    }
}
